package com.sailfish.springbootdemo.service.db2.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sailfish.springbootdemo.configs.UserHeaderHolder;
import com.sailfish.springbootdemo.dao.db5.BoardProportionDao;
import com.sailfish.springbootdemo.dao.db5.H3c08n082CastplateinformationDao;
import com.sailfish.springbootdemo.pojo.db2.FactoryCost;
import com.sailfish.springbootdemo.dao.db2.PcbCostDao;
import com.sailfish.springbootdemo.dao.db2.PcbSonFactoryInfoDao;
import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db2.*;
import com.sailfish.springbootdemo.pojo.db4.Operate;
import com.sailfish.springbootdemo.pojo.db5.BoardProportion;
import com.sailfish.springbootdemo.pojo.db5.H3c08n082Castplateinformation;
import com.sailfish.springbootdemo.service.db2.PcbCostService;
import com.sailfish.springbootdemo.service.db2.PcbParentFactoryInfoService;
import com.sailfish.springbootdemo.service.db2.PcbSpecialProcessService;
import com.sailfish.springbootdemo.service.db4.OperateService;
import com.sailfish.springbootdemo.utils.CommonUtils;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class PcbCostServiceImpl implements PcbCostService {

    @Autowired
    PcbCostDao pcbCostDao;
    @Autowired
    PcbSonFactoryInfoDao pcbSonFactoryInfoDao;
    @Autowired
    PcbSpecialProcessService pcbSpecialProcessService;
    @Autowired
    OperateService operateService;
    @Autowired
    H3c08n082CastplateinformationDao h3c08n082CastplateinformationDao;
    @Autowired
    PcbParentFactoryInfoService pcbParentFactoryInfoService;
    @Autowired
    BoardProportionDao boardProportionDao;

    @Override
    public List<PcbCost> getAll(PcbCost pcbCost) {
        List<PcbCost> byLimit = pcbCostDao.getByLimit(pcbCost);
        List<PcbSonFactoryInfo> allFactorys = pcbSonFactoryInfoDao.getAllByLimit(null);
        Map<Integer, String> map = new HashMap<>();
        for (int i = 0; i < allFactorys.size(); i++) {
            map.put(allFactorys.get(i).getPcbSonFactoryId(), allFactorys.get(i).getSonFactoryName());
        }
        for (int i = 0; i < byLimit.size(); i++) {
            String factoryName = map.get(byLimit.get(i).getFactoryId());
            byLimit.get(i).setFactoryName(factoryName);
        }
        return byLimit;
    }

    @Override
    public List<PcbCost> getByFactory() {
        List<PcbSonFactoryInfo> allFactorys = pcbSonFactoryInfoDao.getAllByLimit(null);
        List<PcbCost> productList = pcbCostDao.getProductList();
        List<PcbCost> list = pcbCostDao.getByLimit(null);
        Map<String, String> map = new HashMap<>();
        for (int i = 0; i < list.size(); i++) {
            String key = list.get(i).getBoardName() + "-" + list.get(i).getVersion() + "-" + list.get(i).getFactoryId();
            if (!map.containsKey(key)) {
                map.put(key, list.get(i).getCost());
            }
        }
        List<PcbCost> result = new ArrayList<>();
        for (int i = 0; i < productList.size(); i++) {
            Map<Integer, String> factoryCostList = new HashMap<>();
            for (PcbSonFactoryInfo sonFac : allFactorys) {
                String key = productList.get(i).getBoardName() + "-" + productList.get(i).getVersion() + "-" + sonFac.getPcbSonFactoryId();
                if (map.containsKey(key)) {
                    factoryCostList.put(sonFac.getPcbSonFactoryId(), map.get(key));
                } else {
                    factoryCostList.put(sonFac.getPcbSonFactoryId(), null);
                }

            }
            PcbCost pcbCostByFactory = new PcbCost();
            pcbCostByFactory.setBoardName(productList.get(i).getBoardName());
            pcbCostByFactory.setVersion(productList.get(i).getVersion());
//            pcbCostByFactory.setFactoryCostList(factoryCostList);
            result.add(pcbCostByFactory);
        }
        return result;
    }

    @Override
    public Result getCostBoardList(String searchK, String searchV, String timeRange1, String timeRange2) {
        return null;
    }

    @Value("${personal.config.httpUrl.getBoardListAxi}")
    String getBoardListApiAxi;

    @Value("${personal.config.httpUrl.getBoardList}")
    String getBoardListApi;

    @Override
    public Result getCostBoardList(String searchK,String searchV,String timeRange1,String timeRange2,Integer page, Integer pageSize) {
        List<PcbCost> result = new ArrayList<>();
        try {
            if(StringUtils.isBlank(searchV)){
                searchV = null;
            }
            else{
                searchV = searchV.toLowerCase();
            }
            Date startTime = null;
            Date endTime = null;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (!StringUtils.isBlank(timeRange1) && !StringUtils.isBlank(timeRange2)) {
                startTime = sdf.parse(timeRange1);
                endTime = sdf.parse(timeRange2);
            }
            String searchCode0301 = "productCode0301".equals(searchK) ? searchV : null;
            String searchVer0301 = "version".equals(searchK) ? searchV : null;
            String searchLayer = "layer".equals(searchK) ? searchV : null;
            String searchLossControl = "lossControl".equals(searchK) ? searchV : null;
            String searchPrintedSheet = "printedSheet".equals(searchK) ? searchV : null;
            String searchSpell = "pinbanfangshi".equals(searchK) ? searchV : null;
            String searchBoardName = "boardName".equals(searchK) ? searchV : null;
            String searchLength = "length".equals(searchK) ? searchV : null;
            String searchWidth = "width".equals(searchK) ? searchV : null;
            String searchThickness = "thickness".equals(searchK) ? searchV : null;
            String searchMinApeInfo = "minApeInfo".equals(searchK) ? searchV : null;
            String searchMaximumAspectRatio = "maximumAspectRatio".equals(searchK) ? searchV : null;
            String searchMinbackdrillstub = "minbackdrillstub".equals(searchK) ? searchV : null;
            String searchMinimpedance = "minimpedance".equals(searchK) ? searchV : null;
            String searchMinviabackdrill2line = "minviabackdrill2line".equals(searchK) ? searchV : null;
            String searchSurfaceTreatment = "surfaceTreatment".equals(searchK) ? searchV : null;
            String searchSpecialProInfo = "specialProInfo".equals(searchK) ? searchV : null;
            //分页
            if (page != null && !CommonUtils.isNumeric(page.toString())) {
                return ResultUtil.error(500, "错误参数page", "Error Param page", null);
            }
            if (pageSize != null && !CommonUtils.isNumeric(pageSize.toString())) {
                return ResultUtil.error(500, "错误参数pageSize", "Error Param pageSize", null);
            }
            int begin = (page == null && pageSize == null) ? 0 : (page - 1) * pageSize;
            List<BoardProportion> boardProportionList1 = boardProportionDao.getByTime(startTime,endTime,searchCode0301,searchVer0301,null,null);
            List<BoardProportion> boardProportionList = (page == null && pageSize == null) ?
            boardProportionDao.getByTimeAll(startTime,endTime,searchCode0301,searchVer0301) : boardProportionDao.getByTime(startTime,endTime,searchCode0301,searchVer0301,begin,pageSize);

            for (int i = 0; i < boardProportionList.size(); i++) {
                PcbCost boardInfo = new PcbCost();
                BoardProportion boardProportion = boardProportionList.get(i);

                boardInfo.setProductCode0301(boardProportion.getNh3cPrintbocoding());
                boardInfo.setVersion(boardProportion.getNh3cPcbrevision());
                boardInfo.setBoardPlacementTime(boardProportion.getNh3cBoTime());

                String ver = boardProportion.getNh3cPcbrevision();
                String productCode0301 = boardInfo.getProductCode0301();
//                List<H3c08n082Castplateinformation> h3c08n082Castplateinformations = h3c08n082CastplateinformationDao.getByNameAndVer(productCode0301, ver,searchLayer,searchLossControl,searchPrintedSheet,
//                        searchPinbanfangshi,searchBoardName,searchLength,searchWidth,searchThickness,searchMinApeInfo,searchMaximumAspectRatio,searchMinbackdrillstub,searchMinimpedance,
//                        searchMinviabackdrill2line,searchSurfaceTreatment,searchSpecialProInfo);
                List<H3c08n082Castplateinformation> h3c08n082Castplateinformations = h3c08n082CastplateinformationDao.getByNameAndVer(productCode0301, ver,null,null,null,
                        null,null,null,null,null,null,null,null,null,
                        null,null,null);
                if(h3c08n082Castplateinformations != null && h3c08n082Castplateinformations.size()>0){
                    H3c08n082Castplateinformation h3c08n082Castplateinformation=h3c08n082Castplateinformations.get(0);
                    boardInfo.setLayer(h3c08n082Castplateinformation.getNh3cLayersNo());
                    boardInfo.setLossControl(h3c08n082Castplateinformation.getNh3cLossControl());
                    boardInfo.setPrintedSheet(h3c08n082Castplateinformation.getNh3cPrintedSheet());
                    //boardInfo.setSpell("");
                    boardInfo.setBoardName(h3c08n082Castplateinformation.getNh3cBoardname());
                    boardInfo.setLength(h3c08n082Castplateinformation.getNh3cBoardLengthCM());
                    boardInfo.setWidth(h3c08n082Castplateinformation.getNh3cBoardWidthCM());
                    boardInfo.setThickness(h3c08n082Castplateinformation.getNh3cBoardThicknessMM());
                    boardInfo.setMinApeInfo(h3c08n082Castplateinformation.getNh3cMinApeInfo());
                    boardInfo.setMaximumAspectRatio(h3c08n082Castplateinformation.getNh3cMaximumAspectRatio());
                    boardInfo.setMinbackdrillstub(h3c08n082Castplateinformation.getNh3cMinbackdrillstub());
                    boardInfo.setMinimpedance(h3c08n082Castplateinformation.getNh3cMinimpedance());
                    boardInfo.setMinviabackdrill2line(h3c08n082Castplateinformation.getNh3cMinviabackdrill2line());
                    boardInfo.setSurfaceTreatment(h3c08n082Castplateinformation.getNh3cSurfaceTreatment());
                    boardInfo.setSpecialProInfo(h3c08n082Castplateinformation.getNh3cSpecialProInfo());
                    boardInfo.setIsSpell(h3c08n082Castplateinformation.getNh3cIsSpell());
                    if(h3c08n082Castplateinformation.getNh3cIsSpell() == null)
                    {
                        boardInfo.setSpell("1*1");
                    }else{
                        boardInfo.setSpell(boardInfo.getIsSpell().equals("true") ?
                                h3c08n082Castplateinformation.getNh3cSpell() : "1 * 1");
                    }
                    boardInfo.setIsFullPressFitBackPlane(h3c08n082Castplateinformation.getNh3cIsFullPressFitBackPlane());
                    boardInfo.setMinVia2line(h3c08n082Castplateinformation.getNh3cMinVia2line());
                    boardInfo.setIsHipottest(h3c08n082Castplateinformation.getNh3cIsHipottest());

                    List<String> boardFactories = h3c08n082CastplateinformationDao.getForeignAssmanByProductCode(boardInfo.getProductCode0301());
                    HashSet<String> seen = new HashSet<>();
                    boardFactories.removeIf(s -> !seen.add(s));
                    if(boardFactories == null || boardFactories.stream().allMatch(Objects::isNull))
                    {
                        boardInfo.setBoardFactories(null);
                    }else {
                        boardInfo.setBoardFactories(boardFactories);
                    }
                }
                if(!StringUtils.isBlank(searchK) && !StringUtils.isBlank(searchV) && !searchK.equals("productCode0301") && !searchK.equals("version")){
                    if(!StringUtils.isBlank(searchLayer) ){
                        if(!StringUtils.isBlank(boardInfo.getLayer()) && boardInfo.getLayer().toLowerCase().contains(searchLayer)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchLossControl)){
                       if(!StringUtils.isBlank(boardInfo.getLossControl()) && boardInfo.getLossControl().toLowerCase().contains(searchLossControl)){
                           result.add(boardInfo);
                       }
                    }
                    else if(!StringUtils.isBlank(searchPrintedSheet)){
                        if(!StringUtils.isBlank(boardInfo.getPrintedSheet()) && boardInfo.getPrintedSheet().toLowerCase().contains(searchPrintedSheet)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchSpell)){
                        if(!StringUtils.isBlank(boardInfo.getSpell()) && boardInfo.getSpell().toLowerCase().contains(searchSpell)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchBoardName) ){
                        if(!StringUtils.isBlank(boardInfo.getBoardName()) && boardInfo.getBoardName().toLowerCase().contains(searchBoardName)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchLength) ){
                        if(!StringUtils.isBlank(boardInfo.getLength()) && boardInfo.getLength().toLowerCase().contains(searchLength)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchWidth) ){
                        if(!StringUtils.isBlank(boardInfo.getWidth()) && boardInfo.getWidth().toLowerCase().contains(searchWidth)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchThickness)){
                        if(!StringUtils.isBlank(boardInfo.getThickness()) && boardInfo.getThickness().toLowerCase().contains(searchThickness)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchMinApeInfo)){
                        if(!StringUtils.isBlank(boardInfo.getMinApeInfo()) && boardInfo.getMinApeInfo().toLowerCase().contains(searchMinApeInfo)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchMaximumAspectRatio) ){
                        if(!StringUtils.isBlank(boardInfo.getMaximumAspectRatio()) && boardInfo.getMaximumAspectRatio().toLowerCase().contains(searchMaximumAspectRatio)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchMinbackdrillstub)){
                        if(!StringUtils.isBlank(boardInfo.getMinbackdrillstub()) && boardInfo.getMinbackdrillstub().toLowerCase().contains(searchMinbackdrillstub)){
                            result.add(boardInfo);
                        }
                    }
                    else  if(!StringUtils.isBlank(searchMinimpedance)){
                        if(!StringUtils.isBlank(boardInfo.getMinimpedance()) && boardInfo.getMinimpedance().toLowerCase().contains(searchMinimpedance)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchMinviabackdrill2line) ){
                        if(!StringUtils.isBlank(boardInfo.getMinviabackdrill2line()) && boardInfo.getMinviabackdrill2line().toLowerCase().contains(searchMinviabackdrill2line)){
                            result.add(boardInfo);
                        }
                    }
                    else  if(!StringUtils.isBlank(searchSurfaceTreatment)){
                        if(!StringUtils.isBlank(boardInfo.getSurfaceTreatment()) && boardInfo.getSurfaceTreatment().toLowerCase().contains(searchSurfaceTreatment)){
                            result.add(boardInfo);
                        }
                    }
                    else if(!StringUtils.isBlank(searchSpecialProInfo) && !StringUtils.isBlank(boardInfo.getSpecialProInfo()) && boardInfo.getSpecialProInfo().toLowerCase().contains(searchSpecialProInfo)){
                        result.add(boardInfo);
                    }
                }
                else{
                    result.add(boardInfo);
                }
            }

            List<PcbCost> pcbCostList = pcbCostDao.getByLimit(null);
            Map<String, FactoryCost> map = new HashMap<>();
            for (int i = 0; i < pcbCostList.size(); i++) {
                String key = pcbCostList.get(i).getProductCode0301() + "-" +  pcbCostList.get(i).getVersion() + "-" + pcbCostList.get(i).getFactoryId();
                if (!map.containsKey(key)) {
                    FactoryCost factoryCost = new FactoryCost();
                    factoryCost.setCostId(pcbCostList.get(i).getPcbCostId());
                    factoryCost.setCost(pcbCostList.get(i).getCost());
                    map.put(key, factoryCost);
                }
            }
            PcbSonFactoryInfo searchF = new PcbSonFactoryInfo();
            searchF.setStatus(1);
            List<PcbSonFactoryInfo> allFactorys = pcbSonFactoryInfoDao.getAllByLimit(searchF);
            for (int i = 0; i < result.size(); i++) {
                List<FactoryCost> factoryCostList = new ArrayList<>();
                for (PcbSonFactoryInfo sonFac : allFactorys) {
                    FactoryCost factoryCost = new FactoryCost();
                    factoryCost.setFactoryId(sonFac.getPcbSonFactoryId());
                    factoryCost.setFactoryName(sonFac.getSonFactoryName());

                    String key = result.get(i).getProductCode0301() + "-" +  result.get(i).getVersion() + "-" + sonFac.getPcbSonFactoryId();
                    if (map.containsKey(key)) {
                        factoryCost.setCost(map.get(key).getCost());
                        factoryCost.setCostId(map.get(key).getCostId());
                    } else {
                        factoryCost.setCost(null);
                    }
                    factoryCostList.add(factoryCost);
                }
                result.get(i).setFactoryCostList(factoryCostList);
            }
            return ResultUtil.tablePageSuccess(page,pageSize,boardProportionList1.size(),result,boardProportionList);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }

    }

    @Value("${personal.config.file.file-save-url}")
    private String rootPath;
    @Override
    public Result output() {
        try{

            final Result result = getCostBoardList(null,null,null,null, null, null);
            if(result.getCode().equals(200)){
                if(result.getData()!=null){
                    HashMap<String, Object> data = (HashMap<String, Object>) result.getData();

                        // 获取 "rows" 键对应的值并进行类型转换
                        Object rowsObj = data.get("rows");

                        // 再次检查是否为空，并且是一个 List 类型
                        if (!(rowsObj instanceof List<?>)) {
                            // 进行更具体的类型转换
                            return ResultUtil.error(500,"getCostBoardList返回的结果中data字段的key为\"rows\"的值不是List类型",
                                    "key named \"rows\" of result's data returned by method getCostBoardList is not a instance of List",null);

                        }

                    @SuppressWarnings("unchecked")
                    List<PcbCost> pcbCostList =  (List<PcbCost>) rowsObj;
                    System.out.println("pcbCost list size:" + ((List<?>) rowsObj).size());
                    Workbook workbook = new XSSFWorkbook();
                    Sheet sheet = workbook.createSheet("Sheet1");
                    XSSFCellStyle setBorder = getStyle1(workbook);//字体加粗
                    XSSFCellStyle setBorder2 = getStyle2(workbook);//字体不加粗
                    XSSFCellStyle setFont = getStyleFont(workbook);
                    final XSSFCellStyle dateStyle = getDateStyle(workbook);

                    Row rowT1 = sheet.createRow(1);
                    Row rowT2 = sheet.createRow(2);
                    Row rowT3 = sheet.createRow(3);

                    Cell cell10 = rowT1.createCell(0);
                    cell10.setCellValue("序号");
                    cell10.setCellStyle(setBorder);
                    Cell cell20 = rowT2.createCell(0);
                    cell20.setCellStyle(setBorder);
                    Cell cell11 = rowT1.createCell(1);
                    cell11.setCellValue("单板名称");
                    cell11.setCellStyle(setBorder);
                    Cell cell21 = rowT2.createCell(1);
                    cell21.setCellStyle(setBorder);
                    Cell cell12 = rowT1.createCell(2);
                    cell12.setCellValue("0301编码");
                    cell12.setCellStyle(setBorder);
                    Cell cell22 = rowT2.createCell(2);
                    cell22.setCellStyle(setBorder);
                    Cell cell13 = rowT1.createCell(3);
                    cell13.setCellValue("单板版本");
                    cell13.setCellStyle(setBorder);
                    Cell cell23 = rowT2.createCell(3);
                    cell23.setCellStyle(setBorder);
                    Cell cell14 = rowT1.createCell(4);
                    cell14.setCellValue("投板日期");
                    cell14.setCellStyle(setBorder);
                    Cell cell24 = rowT2.createCell(4);
                    cell24.setCellStyle(setBorder);
                    Cell cell15 = rowT1.createCell(5);
                    cell15.setCellValue("损耗管控");
                    cell15.setCellStyle(setBorder);
                    Cell cell25 = rowT2.createCell(5);
                    cell25.setCellStyle(setBorder);
                    Cell cell16 = rowT1.createCell(6);
                    cell16.setCellValue("板材信息");
                    cell16.setCellStyle(setBorder);
                    Cell cell26 = rowT2.createCell(6);
                    cell26.setCellStyle(setBorder);
                    Cell cell17 = rowT1.createCell(7);
                    cell17.setCellValue("层数");
                    cell17.setCellStyle(setBorder);
                    Cell cell27 = rowT2.createCell(7);
                    cell27.setCellStyle(setBorder);
                    Cell cell18 = rowT1.createCell(8);
                    cell18.setCellValue("拼版方式");
                    cell18.setCellStyle(setBorder);
                    Cell cell28 = rowT2.createCell(8);
                    cell28.setCellStyle(setBorder);
                    Cell cell19 = rowT1.createCell(9);
                    cell19.setCellValue("板框长度（cm）");
                    cell19.setCellStyle(setBorder);
                    Cell cell29 = rowT2.createCell(9);
                    cell29.setCellStyle(setBorder);
                    Cell cell110 = rowT1.createCell(10);
                    cell110.setCellValue("板框宽度（cm）");
                    cell110.setCellStyle(setBorder);
                    Cell cell210 = rowT2.createCell(10);
                    cell210.setCellStyle(setBorder);
                    Cell cell111 = rowT1.createCell(11);
                    cell111.setCellValue("板厚（mm）");
                    cell111.setCellStyle(setBorder);
                    Cell cell211 = rowT2.createCell(11);
                    cell211.setCellStyle(setBorder);
                    Cell cell112 = rowT1.createCell(12);
                    cell112.setCellValue("最小孔径mil");
                    cell112.setCellStyle(setBorder);
                    Cell cell212 = rowT2.createCell(12);
                    cell212.setCellStyle(setBorder);
                    Cell cell113 = rowT1.createCell(13);
                    cell113.setCellValue("厚径比");
                    cell113.setCellStyle(setBorder);
                    Cell cell213 = rowT2.createCell(13);
                    cell213.setCellStyle(setBorder);
                    Cell cell114 = rowT1.createCell(14);
                    cell114.setCellValue("最小背钻stub/mil");
                    cell114.setCellStyle(setBorder);
                    Cell cell214 = rowT2.createCell(14);
                    cell214.setCellStyle(setBorder);
                    Cell cell115 = rowT1.createCell(15);
                    cell115.setCellValue("最小阻抗公差要求/%");
                    cell115.setCellStyle(setBorder);
                    Cell cell215 = rowT2.createCell(15);
                    cell215.setCellStyle(setBorder);
                    Cell cell116 = rowT1.createCell(16);
                    cell116.setCellValue("最小走线到背钻孔壁距离/mil");
                    cell116.setCellStyle(setBorder);
                    Cell cell216 = rowT2.createCell(16);
                    cell216.setCellStyle(setBorder);
                    Cell cell117 = rowT1.createCell(17);
                    cell117.setCellValue("表面处理");
                    cell117.setCellStyle(setBorder);
                    Cell cell217 = rowT2.createCell(17);
                    cell217.setCellStyle(setBorder);
                    Cell cell118 = rowT1.createCell(18);
                    cell118.setCellValue("特殊工艺");
                    cell118.setCellStyle(setBorder);
                    Cell cell218 = rowT2.createCell(18);
                    cell218.setCellStyle(setBorder);
                    //新增字段 2024/12/30 author:zyqin
                    Cell cell119 = rowT1.createCell(19);
                    cell119.setCellValue("是否纯压接背板");
                    cell119.setCellStyle(setBorder);
                    Cell cell219 = rowT2.createCell(19);
                    cell219.setCellStyle(setBorder);
                    Cell cell120 = rowT1.createCell(20);
                    cell120.setCellValue("是否需要耐压测试");
                    cell120.setCellStyle(setBorder);
                    Cell cell220 = rowT2.createCell(20);
                    cell220.setCellStyle(setBorder);
                    Cell cell121 = rowT1.createCell(21);
                    cell121.setCellValue("走线到孔壁最小距离/mil");
                    cell121.setCellStyle(setBorder);
                    Cell cell221 = rowT2.createCell(21);
                    cell221.setCellStyle(setBorder);
                    Cell cell122 = rowT1.createCell(22);
                    cell122.setCellValue("投板板厂");
                    cell122.setCellStyle(setBorder);
                    Cell cell222 = rowT2.createCell(22);
                    cell222.setCellStyle(setBorder);

//                    List<Integer> pcbSpecialProcessInfo_Ids = new ArrayList<>();
                    List<Integer> pcbFactoryIds_new = new ArrayList<>();

                    int columIndex = 23;
                    List<PcbParentFactoryInfo> pcbParentFactoryInfoList = pcbParentFactoryInfoService.getAll(null, null, null, null, null, null, null, null, null, null, null, null, 1, null);

                    for(int i=0;i<pcbParentFactoryInfoList.size();i++){
                        Cell cell1i = rowT1.createCell(columIndex);
                        cell1i.setCellValue(pcbParentFactoryInfoList.get(i).getCompanyName());
                        cell1i.setCellStyle(setBorder);
                        int startIndexT = columIndex;
                        List<PcbSonFactoryInfo> sonFactoryInfos = pcbParentFactoryInfoList.get(i).getSonFactoryInfos();
                        if (sonFactoryInfos != null && sonFactoryInfos.size() > 0){
                            for (int j = 0; j < sonFactoryInfos.size(); j++) {
                                Cell cell6 = rowT2.createCell(columIndex);
                                cell6.setCellValue(sonFactoryInfos.get(j).getSonFactoryName());
                                cell6.setCellStyle(setBorder);

                                if (j != 0) {
                                    Cell cell123 = rowT1.createCell(columIndex);
                                    cell123.setCellStyle(setBorder);
                                }
                                columIndex++;

                                pcbFactoryIds_new.add(sonFactoryInfos.get(j).getPcbSonFactoryId());
                            }
                            CellRangeAddress region3 = new CellRangeAddress(1, 1, startIndexT, columIndex - 1);
                            if (columIndex - 1 > startIndexT) {
                                sheet.addMergedRegion(region3);
                            }
                        }
                        else {
                            Cell cell2i = rowT2.createCell(columIndex);
                            cell2i.setCellStyle(setBorder);
                            columIndex++;
                        }
                    }
                    int colCount = columIndex;
                    int rowIndex = 3;
                    int startIndex0 ;
                    for(int i=0;i<pcbCostList.size();i++){
                        final PcbCost pcbCost = pcbCostList.get(i);
                        startIndex0 = rowIndex;
                        Row row = sheet.createRow(rowIndex);
                        rowIndex++;
                        Cell celli0 = row.createCell(0);
                        celli0.setCellValue((i+1));
                        Cell celli1 = row.createCell(1);
                        celli1.setCellValue(pcbCost.getBoardName());
                        Cell celli2 = row.createCell(2);
                        celli2.setCellValue(pcbCost.getProductCode0301());
                        Cell celli3 = row.createCell(3);
                        celli3.setCellValue(pcbCost.getVersion());
                        Cell celli4 = row.createCell(4);
                        celli4.setCellValue(pcbCost.getBoardPlacementTime());
                        celli4.setCellStyle(dateStyle);
                        Cell celli5 = row.createCell(5);
                        celli5.setCellValue(pcbCost.getLossControl());
                        Cell celli6 = row.createCell(6);
                        celli6.setCellValue(pcbCost.getPrintedSheet());
                        Cell celli7 = row.createCell(7);
                        celli7.setCellValue(pcbCost.getLayer());
                        Cell celli8 = row.createCell(8);
                        celli8.setCellValue(pcbCost.getSpell());
                        Cell celli9 = row.createCell(9);
                        celli9.setCellValue(pcbCost.getLength());
                        Cell celli10 = row.createCell(10);
                        celli10.setCellValue(pcbCost.getWidth());
                        Cell celli11 = row.createCell(11);
                        celli11.setCellValue(pcbCost.getThickness());
                        Cell celli12 = row.createCell(12);
                        celli12.setCellValue(pcbCost.getMinApeInfo());
                        Cell celli13 = row.createCell(13);
                        celli13.setCellValue(pcbCost.getMaximumAspectRatio());
                        Cell celli14 = row.createCell(14);
                        celli14.setCellValue(pcbCost.getMinbackdrillstub());
                        Cell celli15 = row.createCell(15);
                        celli15.setCellValue(pcbCost.getMinimpedance());
                        Cell celli16 = row.createCell(16);
                        celli16.setCellValue(pcbCost.getMinviabackdrill2line());
                        Cell celli17 = row.createCell(17);
                        celli17.setCellValue(pcbCost.getSurfaceTreatment());
                        Cell celli18 = row.createCell(18);
                        celli18.setCellValue(pcbCost.getSpecialProInfo());
                        Cell celli19 = row.createCell(19);
                        celli19.setCellValue(pcbCost.getIsFullPressFitBackPlane());
                        Cell celli20 = row.createCell(20);
                        celli20.setCellValue(pcbCost.getIsHipottest());
                        Cell celli21 = row.createCell(21);
                        celli21.setCellValue(pcbCost.getMinVia2line());
                        Cell celli22 = row.createCell(22);
                        List<String> boardFactories = pcbCost.getBoardFactories();
                        if(boardFactories != null)
                        {
                            HashSet<String> seen = new HashSet<>();
                            boardFactories.removeIf(s -> !seen.add(s));
                            String joined = boardFactories.stream().collect(Collectors.joining(","));
                            celli22.setCellValue(joined);
                        }
//                        Map<Integer, String> specialProcessList = pcbCost.getSpecialProcessList();
//                        for(int j=0; j< pcbSpecialProcessInfo_Ids.size();j++){
//                            String value = specialProcessList.get(pcbSpecialProcessInfo_Ids.get(j));
//                            Cell cellij = row.createCell(19 + j );
//                            cellij.setCellValue(value);
//                        }

                        final List<FactoryCost> factoryCostList = pcbCost.getFactoryCostList();
                        for(int j=0; j< pcbFactoryIds_new.size();j++){
                            Cell cellij = row.createCell(23  + j );//+ pcbSpecialProcessInfo_Ids.size()
                            Integer fid = pcbFactoryIds_new.get(j);
                            List<FactoryCost> collect = factoryCostList.stream().filter(x -> x.getFactoryId().equals(fid)).collect(Collectors.toList());
                            if(collect != null && collect.size() > 0){

                                cellij.setCellValue(collect.get(0).getCost());
                            }
                            else{
                                cellij.setCellValue("");
                            }
                        }
                    }

                sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 0));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 1, 1));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 2, 2));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 3, 3));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 4, 4));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 5, 5));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 6, 6));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 7, 7));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 8, 8));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 9, 9));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 10, 10));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 11, 11));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 12, 12));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 13, 13));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 14, 14));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 15, 15));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 16, 16));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 17, 17));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 18, 18));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 19, 19));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 20, 20));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 21, 21));
                sheet.addMergedRegion(new CellRangeAddress(1, 2, 22, 22));
//                for(int i=0;i<pcbSpecialProcessInfoList.size();i++){
//                    sheet.addMergedRegion(new CellRangeAddress(1, 2, 19+i, 19+i));
//                }
                    for(int j=0; j< colCount; j++){
                        if(j == 4){
                            sheet.setColumnWidth(j, 20 * 256);
                        }
                        else{
                            sheet.setColumnWidth(j, 15 * 256);
                        }

                    }
                for(int i=0; i<pcbCostList.size(); i++){
                    Row row = sheet.getRow(i+3);
                    for(int j=0; j< colCount; j++){
                        if(j == 4){
                            continue;
                        }
                        Cell celli = row.getCell(j);
                        if (celli == null) {
                            celli = row.createCell(j);
                            celli.setCellStyle(setBorder2);
                        }
                        else {
                            celli.setCellStyle(setBorder2);
                        }
                    }
                }
                    // 导出Excel文件
                    String filename = "能力数据" + String.valueOf(System.currentTimeMillis());
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    String format = sdf.format(new Date());
                    String filePath = rootPath + "pcb\\" + format + "\\" + filename + ".xlsx";
                    File folder = new File(rootPath + "pcb\\" + format);
                    if (!folder.isDirectory()) {
                        folder.mkdirs();
                    }
                    FileOutputStream outputStream = new FileOutputStream(filePath);
                    workbook.write(outputStream);
                    workbook.close();
                    outputStream.close();
                    return ResultUtil.success(filePath);
                }
                else {
                    return result;
                }

            }
            else {
                return result;
            }
        }
        catch (Exception e){
            e.printStackTrace();
            return ResultUtil.error(500,e.getMessage(),e.getMessage(),null);
        }

    }

    public XSSFCellStyle getStyle1(Workbook workbook) {
        XSSFCellStyle setBorder = (XSSFCellStyle) workbook.createCellStyle();
        setBorder.setBorderBottom(BorderStyle.THIN);
        setBorder.setBorderLeft(BorderStyle.THIN);
        setBorder.setBorderRight(BorderStyle.THIN);
        setBorder.setBorderTop(BorderStyle.THIN);
        setBorder.setVerticalAlignment(VerticalAlignment.CENTER);
        setBorder.setAlignment(HorizontalAlignment.LEFT);
        //创建字体 加粗
        XSSFFont font = (XSSFFont) workbook.createFont();
        font.setBold(true);
        font.setFontHeight(11);
        setBorder.setFont(font);
        return setBorder;
    }
    //创建日期格式
    public XSSFCellStyle getDateStyle(Workbook workbook) {
        XSSFCellStyle setBorder2 = (XSSFCellStyle) workbook.createCellStyle();
        setBorder2.setBorderBottom(BorderStyle.THIN);
        setBorder2.setBorderLeft(BorderStyle.THIN);
        setBorder2.setBorderRight(BorderStyle.THIN);
        setBorder2.setBorderTop(BorderStyle.THIN);
        setBorder2.setVerticalAlignment(VerticalAlignment.CENTER);
        setBorder2.setAlignment(HorizontalAlignment.LEFT);
        setBorder2.setDataFormat(workbook.createDataFormat().getFormat("yyyy-MM-dd HH:mm:ss"));
        return setBorder2;
    }

    public XSSFCellStyle getStyle2(Workbook workbook) {
        XSSFCellStyle setBorder2 = (XSSFCellStyle) workbook.createCellStyle();
        setBorder2.setBorderBottom(BorderStyle.THIN);
        setBorder2.setBorderLeft(BorderStyle.THIN);
        setBorder2.setBorderRight(BorderStyle.THIN);
        setBorder2.setBorderTop(BorderStyle.THIN);
        setBorder2.setVerticalAlignment(VerticalAlignment.CENTER);
        setBorder2.setAlignment(HorizontalAlignment.LEFT);
        return setBorder2;
    }
    public XSSFCellStyle getStyleFont(Workbook workbook) {
        XSSFCellStyle setBorder = (XSSFCellStyle) workbook.createCellStyle();
        //创建字体 加粗
        XSSFFont font = (XSSFFont) workbook.createFont();
        font.setBold(true);
        font.setFontHeight(11);
        setBorder.setFont(font);
        return setBorder;
    }

    public XSSFCellStyle getStyleColor(Workbook workbook, short colorIndex) {
        XSSFCellStyle styleRed = (XSSFCellStyle) workbook.createCellStyle();
        styleRed.setBorderBottom(BorderStyle.THIN);
        styleRed.setBorderLeft(BorderStyle.THIN);
        styleRed.setBorderRight(BorderStyle.THIN);
        styleRed.setBorderTop(BorderStyle.THIN);
        styleRed.setVerticalAlignment(VerticalAlignment.CENTER);
        styleRed.setAlignment(HorizontalAlignment.LEFT);
        styleRed.setFillForegroundColor(colorIndex);
        styleRed.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        return styleRed;
    }
//    private List<String> getSpecialProcessList() throws Exception {
//        String md5Sign = "6244832a706bbb2c81fb093367027f56";
//        MultipartEntityBuilder params = MultipartEntityBuilder.create();
//        params.addTextBody("signature", md5Sign);
//        String res = HttpUtil.sendPostFormData(getBoardListApi, params);
//
//        JSONObject jsonObject = JSON.parseObject(res);
//        List<String> boardParamKeys = new ArrayList<>();
//        Map<Integer,List<String>> map = new HashMap<>();
//        if(jsonObject.getInteger("code") == 200){
//            JSONArray jsonArray = jsonObject.getJSONArray("data");
//            for(int i=0; i < jsonArray.size(); i++){
//                JSONObject jo_project = jsonArray.getJSONObject(i);
//                Integer projectId = jo_project.getInteger("projectId");
//                JSONArray boardParamTypeList = jo_project.getJSONArray("boardParamTypeList");
//                if(boardParamTypeList != null && boardParamTypeList.size() > 0){
//                    for(int j=0; j<boardParamTypeList.size(); j++){
//                        JSONObject jo_boardType = boardParamTypeList.getJSONObject(j);
//                        String boardParamTypeName = jo_boardType.getString("boardParamTypeName");
//                        Integer boardParamTypeId = jo_boardType.getInteger("boardParamTypeId");
//                        JSONArray boardParamList = jo_boardType.getJSONArray("boardParamList");
//                        if(boardParamTypeId == 4)//boardParamTypeName.equals("单板工艺特征信息")
//                        {
//                            for(int k=0; k<boardParamList.size(); k++){
//                               JSONObject jo_process = boardParamList.getJSONObject(k);
//                               String boardParamName = jo_process.getString("boardParamName");
//                               String boardParamKey = jo_process.getString("boardParamKey");
//                               boardParamKeys.add(boardParamKey);
//                            }
//                        }
//                    }
//                }
//            }
//        }
//        return boardParamKeys;
//    }

    @Transactional(transactionManager = "MysqlTransactionManager2")
    @Override
    public Result insert(String data) {
        try {
            JSONObject jsonObject = JSONObject.parseObject(data);
            String mode = jsonObject.getString("mode");
            JSONObject jsonObject2 = jsonObject.getJSONObject("list");
            if (jsonObject2 == null) {
                return ResultUtil.error(500, "list 为空", "list is null", null);
            }
//            Integer projectId = jsonObject.getInteger("projectId");
            String boardName = jsonObject.getString("boardName");
            String version = jsonObject.getString("version");
            String productCode0301 = jsonObject.getString("productCode0301");
            String layer = jsonObject.getString("layer");
            String length = jsonObject.getString("length");
            String width = jsonObject.getString("width");
            String thickness = jsonObject.getString("thickness");

            JSONArray costArray = jsonObject.getJSONArray("list");
//            if (projectId == null) {
//                return ResultUtil.error(500, "参数projectId为空", "param projectId is null", null);
//            }

            String userId = UserHeaderHolder.getUserId();
            for (int i = 0; i < costArray.size(); i++) {
                JSONObject jo = costArray.getJSONObject(i);
                Integer factoryId = jo.getInteger("factoryId");
                if (factoryId == null) {
                    return ResultUtil.error(500, "参数factoryId为空", "param factoryId is null", null);
                }
                String cost = jo.getString("cost");
                Integer costId = jo.getInteger("costId");
                PcbCost pcbCost = new PcbCost();
                pcbCost.setCost(cost);
                pcbCost.setFactoryId(factoryId);
                pcbCost.setBoardName(boardName);
                pcbCost.setVersion(version);
//                pcbCost.setProjectId(projectId);
                pcbCost.setProductCode0301(productCode0301);
                pcbCost.setLayer(layer);
                pcbCost.setWidth(width);
                pcbCost.setLength(length);
                pcbCost.setThickness(thickness);
                if (costId == null) {
                    pcbCost.setCreateTime(new Date());
                    int count = pcbCostDao.insert(pcbCost);
                    if (count > 0) {
                        operateService.addOperate(new Operate(2, Integer.parseInt(userId), "PCB成本管理", 1, 1, new Date(), null, JSONObject.toJSONString(pcbCost)));
                        return ResultUtil.success(null);
                    } else {
                        return ResultUtil.error(500, "操作失败", "Operate Fail", null);
                    }
                } else {
                    pcbCost.setPcbCostId(costId);
                    pcbCost.setUpdateTime(new Date());
                    String oldData = JSONObject.toJSONString(pcbCostDao.getById(costId));
                    int count = pcbCostDao.update(pcbCost);
                    if (count > 0) {
                        String newData = JSONObject.toJSONString(pcbCostDao.getById(costId));
                        operateService.addOperate(new Operate(2, Integer.parseInt(userId), "PCB成本管理", 3, 1, new Date(), oldData, newData));
                        return ResultUtil.success(null);
                    } else {
                        return ResultUtil.error(500, "操作失败", "Operate Fail", null);
                    }
                }
            }
            return ResultUtil.success(null);
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }

    }

    @Transactional(transactionManager = "MysqlTransactionManager2")
    @Override
    public Result update(String data) {
        try {
            JSONObject jsonObject = JSONObject.parseObject(data);
            JSONArray costArray = jsonObject.getJSONArray("list");
            JSONObject jsonObject1 = jsonObject.getJSONObject("projectList");
            if (costArray == null) {
                return ResultUtil.error(500, "list 为空", "list is null", null);
            }
            if (jsonObject1 == null) {
                return ResultUtil.error(500, "projectList 为空", "projectList is null", null);
            }
//            Integer projectId = jsonObject1.getInteger("projectId");
            String boardName = jsonObject1.getString("boardName");
            String version = jsonObject1.getString("version");
            String productCode0301 = jsonObject1.getString("productCode0301");
            String layer = jsonObject1.getString("layer");
            String length = jsonObject1.getString("length");
            String width = jsonObject1.getString("width");
            String thickness = jsonObject1.getString("thickness");

//            if (projectId == null) {
//                return ResultUtil.error(500, "参数projectId为空", "param projectId is null", null);
//            }

            String userId = UserHeaderHolder.getUserId();
            for (int i = 0; i < costArray.size(); i++) {
                JSONObject jo = costArray.getJSONObject(i);
                Integer factoryId = jo.getInteger("factoryId");
                if (factoryId == null) {
                    return ResultUtil.error(500, "参数factoryId为空", "param factoryId is null", null);
                }
                String cost = jo.getString("cost");
                Integer costId = jo.getInteger("costId");
                PcbCost pcbCost = new PcbCost();
                pcbCost.setCost(cost);
                pcbCost.setFactoryId(factoryId);
                pcbCost.setBoardName(boardName);
                pcbCost.setVersion(version);
//                pcbCost.setProjectId(projectId);
                pcbCost.setProductCode0301(productCode0301);
                pcbCost.setLayer(layer);
                pcbCost.setWidth(width);
                pcbCost.setLength(length);
                pcbCost.setThickness(thickness);
                if (costId == null) {
                    pcbCost.setCreateTime(new Date());
                    int count = pcbCostDao.insert(pcbCost);
                    if (count > 0) {
                        operateService.addOperate(new Operate(2, Integer.parseInt(userId), "PCB成本管理", 1, 1, new Date(), null, JSONObject.toJSONString(pcbCost)));
                    } else {
                        return ResultUtil.error(500, "操作失败", "Operate Fail", null);
                    }
                } else {
                    pcbCost.setPcbCostId(costId);
                    pcbCost.setUpdateTime(new Date());
                    String oldData = JSONObject.toJSONString(pcbCostDao.getById(costId));
                    int count = pcbCostDao.update(pcbCost);
                    if (count > 0) {
                        String newData = JSONObject.toJSONString(pcbCostDao.getById(costId));
                        operateService.addOperate(new Operate(2, Integer.parseInt(userId), "PCB成本管理", 3, 1, new Date(), oldData, newData));
                    } else {
                        return ResultUtil.error(500, "操作失败", "Operate Fail", null);
                    }
                }
            }
            return ResultUtil.success(null);
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }

    }

    @Transactional(transactionManager = "MysqlTransactionManager2")
    @Override
    public Result delete(Integer id) {
        try {
            if (id == null) {
                return ResultUtil.error(500, "参数id为空", "param id is null", null);
            }
            String userId = UserHeaderHolder.getUserId();
            String oldData = JSONObject.toJSONString(pcbCostDao.getById(id));
            int count = pcbCostDao.delete(id);
            if (count > 0) {
                operateService.addOperate(new Operate(2, Integer.parseInt(userId), "PCB成本管理", 2, 1, new Date(), oldData, null));
                return ResultUtil.success(null);
            } else {
                return ResultUtil.error(500, "操作失败", "Operate Fail", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result deletePcbCostByProduct(String productName, String productVersion) {
        try {
            if (StringUtils.isBlank(productName)) {
                return ResultUtil.error(500, "参数productName为空", "param productName is null", null);
            }
            if (StringUtils.isBlank(productVersion)) {
                return ResultUtil.error(500, "参数productVersion为空", "param productVersion is null", null);
            }
            String userId = UserHeaderHolder.getUserId();
            PcbCost search = new PcbCost();
            search.setBoardName(productName);
            search.setVersion(productVersion);
            List<PcbCost> byLimit = pcbCostDao.getByLimit(search);
            String oldData = JSONObject.toJSONString(byLimit);
            int count = pcbCostDao.deleteByProduct(productName, productVersion);
            if (count > 0) {
                operateService.addOperate(new Operate(2, Integer.parseInt(userId), "PCB成本管理", 2, 1, new Date(), oldData, null));
                return ResultUtil.success(null);
            } else {
                return ResultUtil.error(500, "操作失败", "Operate Fail", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }
}
